#!/bin/bash

#Desc:add or del userinfo
#Author:xttcqw.cn
#Usage:$1 a/add|d/del userinfo $2...userName
#Update:2020-8-26


operationtype=
paramenters=(${@})

#$1 is shell's $1
#return 1 input error,2 add user, 3 del user
checkParamenter(){
	if [ "$1" == "a" ]; then
		return 2
	elif [ "$1" == "d" ]; then
		return 3
	else  
		return  1
	fi
}

#add user 
#$1 is shell's ${*}
adduser(){
	len=${#paramenters[*]}
	for ((i=1;i<len;i++))
	do
	useradd -s /usr/bin/bash  ${paramenters[$i]} &>/dev/null
	if [ $? -eq 0 ]
	then
		#set first passwd 123
		echo "123" | passwd --stdin $i &>/dev/null
		chage -d 0 $i &>/dev/null
	fi
	done 
}
deluser(){
	len=${#paramenters[*]}
	for ((i=1;i<len;i++)); do
	userdel -r  ${paramenters[$i]} &>/dev/null
	done 
}

main(){
	checkParamenter $1
	flag=$?
	if [ $flag -eq 1 ]; then
		echo "请输入正确的参数"
	elif [ $flag -eq 2 ]; then
		adduser
	else
		deluser
	fi
}

main $1
